package com.likan.chqjtgc.service.impl;

import com.likan.chqjtgc.commons.PageVo;
import com.likan.chqjtgc.entity.BasicOperatLog;
import com.likan.chqjtgc.mapper.BasicOperatLogMapper;
import com.likan.chqjtgc.service.BasicOperatLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 系统操作日志表 服务实现类
 * </p>
 *
 * @author lxh
 * @since 2021-01-10
 */
@Service
@Transactional(rollbackFor = {Exception.class})
public class BasicOperatLogServiceImpl extends ServiceImpl<BasicOperatLogMapper, BasicOperatLog> implements BasicOperatLogService {

    @Autowired
    private BasicOperatLogMapper baseMapper;

    @Override
    public IPage<BasicOperatLog> findListByPage(PageVo< BasicOperatLog> page){
           Page<BasicOperatLog> pageInfo = new Page<>(page.getCurrent(), page.getSize());
       QueryWrapper<BasicOperatLog> wrapper = new QueryWrapper<>();
        //todo:构造查询参数 根据业务添加

       if (StringUtils.isNotBlank(page.getSortField())){
           wrapper.orderBy(true,0!=page.getDirection() ,page.getSortField());
       }else {
           wrapper.orderByDesc("id");
       }
        IPage<BasicOperatLog> iPage = baseMapper.selectPage(pageInfo, wrapper);
        return iPage;
    }

    @Override
    public Boolean add(BasicOperatLog basicOperatLog){
        baseMapper.insert(basicOperatLog);
        return true;
    }

    @Override
    public Boolean delete(Long id){
        baseMapper.deleteById(id);
        return true;
    }

    @Override
    public Boolean updateData(BasicOperatLog basicOperatLog){
        baseMapper.updateById(basicOperatLog);
        return true;
    }

    @Override
    public BasicOperatLog findById(Long id){
        BasicOperatLog basicOperatLog = baseMapper.selectById(id);
        return basicOperatLog;
    }
}
